<?php

namespace App\Http\Controllers\Api;

use Illuminate\Http\Request;

use App\Models\Wx\WxCustomer;

use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Redis as Redis;

class SsoController extends Controller
{

    /**
     * 单点登录，获取会员信息
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse|\Symfony\Component\HttpFoundation\Response
     */
    public function get(Request $request)
    {

        $session_id = $request->input('session_id');
        if (empty($session_id)) {
            return response()->json(['code' => 100000, 'message' => '缺少参数：session_id']);
        }

        //获取会员信息
        $customer = Redis::get('FX_SESSION_DATA_' . $session_id);
        if (!$customer) {
            return response()->json(['code' => 100001, 'message' => '会员信息没有找到']);
        }
        $customer = json_decode($customer,true);

        $return = [
            'user_id' => $customer['pcustID'],
            'mobile' => $customer['mobile']
        ];

        //查询微信会员信息
        $wx_customer = WxCustomer::select('headPic')->where('pcustID', $customer['pcustID'])->first();
        if ($wx_customer) {
            $return['head_pic'] = $wx_customer->headPic;
        }

        return response()->json(['code' => 200, 'message' => 'OK', 'data' => $return]);

    }

}
